const Koa = require("koa");
const path = require('path');
const serve = require('koa-static');

function getIPAdress() {
    var interfaces = require('os').networkInterfaces();
    for (var devName in interfaces) {
        var iface = interfaces[devName];
        for (var i = 0; i < iface.length; i++) {
            var alias = iface[i];
            if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                return alias.address;
            }
        }
    }
}

var port = process.argv[3] || 8080;

const app = new Koa();
const main = serve(path.join(__dirname));
app.use(main);
console.log("服务已启动：" + getIPAdress() + ":" + port)

app.listen(port);